package com.xcexample.electronicclasscard

import android.app.Application
import android.os.Environment
import com.tencent.mmkv.MMKV
import com.xcexample.electronicclasscard.log.FileLogUtils
import com.xcexample.electronicclasscard.log.MyCrashHandler
import java.io.File

class App : Application() {
    private val TAG: String = App.toString()
    override fun onCreate() {
        super.onCreate()
        MMKV.initialize(this)
        instance = this
        initLog()
        initCrash()
    }

    private fun initCrash() {
        val handler = MyCrashHandler()
        Thread.setDefaultUncaughtExceptionHandler(handler)
    }

    private fun initLog() {
        val cacheDir = getExternalFilesDir(null)!!.path + File.separator + "log"
        val logFilePath = Environment.getExternalStorageDirectory()
            .toString() + File.separator + "Intehel" + File.separator + "log"
        FileLogUtils.setLogDir(cacheDir)
        // 为了保护隐私和保证log的整洁，正式版上只打比warn高的log，即warn, error和assert
        FileLogUtils.setLogLevel(FileLogUtils.LogLevel.INFO)
    }
    companion object {
        lateinit var instance: App

    }
}